package com.huawei.hwid.d;

import android.content.Context;
import android.text.TextUtils;
import com.huawei.hwid.core.d.b;
import com.huawei.hwid.core.d.b.e;
import com.huawei.hwid.core.datatype.HwAccount;
import java.util.ArrayList;
import java.util.HashMap;

public final class a {
    private static a a = null;
    private Context b;
    private HwAccount c;
    private HashMap<String, String> d = new HashMap();

    private a(Context context) {
        this.b = context;
    }

    public static a a(Context context) {
        a aVar;
        synchronized (a.class) {
            if (a == null) {
                a = new a(context.getApplicationContext());
            }
            aVar = a;
        }
        return aVar;
    }

    public void a() {
        e.b("HwIDMemCache", "initHwAccountMemCache", true);
        ArrayList a = com.huawei.hwid.c.a.a(this.b).a(this.b);
        if (a.size() > 0) {
            this.c = (HwAccount) a.get(0);
        } else {
            e.b("HwIDMemCache", "file has no account", true);
        }
    }

    public void a(HwAccount hwAccount) {
        e.b("HwIDMemCache", "saveHwAccountToCache", true);
        if (b.a(hwAccount)) {
            this.c = hwAccount;
            return;
        }
        e.d("HwIDMemCache", "save hwAccount is null", true);
        this.c = null;
    }

    public HwAccount b() {
        if (this.c == null) {
            a();
        }
        return this.c;
    }

    public void a(String str, String str2) {
        if (!TextUtils.isEmpty(str2)) {
            this.d.put(str, str2);
        }
    }

    public void c() {
        this.d.clear();
    }

    public String a(String str) {
        return this.d.get(str) == null ? "" : (String) this.d.get(str);
    }
}
